package com.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Aspect 定义改类为切面类
 */
@Aspect
public class TrxAspect {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Pointcut("execution(public void com.aop.BusiessClass.*(..))")
    public void pointCut(){

    }

    /**
     * 开启事物
     * @param joinPoint
     */
    @Before("pointCut()")
    public void beginTrx(JoinPoint joinPoint){
        logger.info("===============执行beginTrx方法===============");

    }

    /**
     * 执行事物
     * @param joinPoint
     */
    @After("pointCut()")
    public void doTrx(JoinPoint joinPoint){
        logger.info("===============执行doTrx方法===============");

    }

    @AfterReturning("pointCut()")
    public void aferReturn(JoinPoint joinPoint) {
        logger.info("===============执行aferReturn方法===============");
    }

    @Around("pointCut()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        logger.info("===============执行前===============");
        proceedingJoinPoint.proceed();
        logger.info("===============执行后===============");

    }



}
